﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;


namespace TestDxfDocument
{
    class _36485
    {
        public static void Standard36485_1(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
                                                                           //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double b = 8; 
            double l3 = 6.4;
            double f = 8.5;
            double h2 = 8;
            double l2= 12;
            double r3= 0.4;
            //坐标
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = fun.Polar(v1, 90 * pi / 180, l3);
            Vector2 v3 = fun.Polar(v2, 170 * pi / 180, l3);
            Vector2 v4 = fun.Polar(v3, -90 * pi / 180, l3);
            Vector2 v5 = fun.Polar(v1, 90 * pi / 180, r3 / Math.Tan(40 * pi / 180));
            Vector2 v6 = fun.Polar(v2, -90 * pi / 180, r3 / Math.Tan(50 * pi / 180));
            Vector2 v7 = fun.Polar(v2, 170 * pi / 180, r3 / Math.Tan(50 * pi / 180));
            Vector2 v8 = fun.Polar(v3, -10 * pi / 180, r3 / Math.Tan(40 * pi / 180));
            Vector2 v9 = fun.Polar(v3, -90 * pi / 180, r3 / Math.Tan(40 * pi / 180));
            Vector2 v10 = fun.Polar(v4, 90 * pi / 180, r3 / Math.Tan(50 * pi / 180));
            Vector2 v11 = fun.Polar(v4, -10 * pi / 180, r3 / Math.Tan(50 * pi / 180));
            Vector2 v12 = fun.Polar(v1, 170 * pi / 180, r3 / Math.Tan(40 * pi / 180));
            Vector2 v13 = fun.Polar(v2, 170 * pi / 180, (f-b) / Math.Cos(10 * pi / 180));
            Vector2 v14 = new Vector2(v13.X, v1.Y + l2);
            Vector2 v15 = fun.Polar(v14, 90 * pi / 180, 35);
            Vector2 v16 = fun.Polar(v15, 180 * pi / 180, b);
            Vector2 v17 = fun.Polar(v14, 180 * pi / 180, b);
            Vector2 v18 = fun.Polar(v17, -90 * pi / 180, 9.97);
            Vector2 v19 = fun.Polar(v10, 90 * pi / 180, 0.5);
            Vector2 v20 = fun.Polar(v15, -90 * pi / 180, 6.5);
            Vector2 v21 = fun.Polar(v16, -90 * pi / 180, 6.5);
            Vector2 v22 = fun.Polar(v21, -90 * pi / 180, h2);
            Vector2 v23 = fun.Polar(v20, -90 * pi / 180, h2);
            Vector2 v24 = fun.Polar(v22, -90 * pi / 180, 6.35);
            Vector2 v25 = fun.Polar(v24, -4 * pi / 180, 1.917);
            Vector2 v26 = fun.Polar(v25, -30 * pi / 180, 2.14);
            Vector2 v27 = fun.Polar(v26, 1 * pi / 180, 2.75);
            Vector2 v28 = fun.Polar(v23, -90 * pi / 180, 8.5);
            Vector2 v29 = fun.Polar(v24, -90 * pi / 180, 1);
            Vector2 v30 = fun.Polar(v25, -90 * pi / 180, 1);
            Vector2 v31 = fun.Polar(v26, -90 * pi / 180, 1);
            Vector2 v32 = fun.Polar(v27, -90 * pi / 180, 1);
            Vector2 v33 = fun.Polar(v28, -90 * pi / 180, 1);


            LwPolyline line1 = new LwPolyline();
            line1.Vertexes.Add(new LwPolylineVertex(v5));
            line1.Vertexes.Add(new LwPolylineVertex(v6));
            line1.Vertexes.Add(new LwPolylineVertex(v7));
            line1.Vertexes[1].Bulge = Math.Tan(80 * pi / 180 / 4);
            line1.Vertexes.Add(new LwPolylineVertex(v8));
            line1.Vertexes.Add(new LwPolylineVertex(v9));
            line1.Vertexes[3].Bulge = Math.Tan(100 * pi / 180 / 4);
            line1.Vertexes.Add(new LwPolylineVertex(v10));
            line1.Vertexes.Add(new LwPolylineVertex(v11));
            line1.Vertexes[5].Bulge = Math.Tan(80 * pi / 180 / 4);
            line1.Vertexes.Add(new LwPolylineVertex(v12));
            line1.Vertexes.Add(new LwPolylineVertex(v5));
            line1.Vertexes[7].Bulge = Math.Tan(100 * pi / 180 / 4);
            line1.Layer = contour;
            line1.Lineweight = Lineweight.W50;
            dxf.AddEntity(line1);
            Line line2 = new Line(v13, v33);
            line2.Layer = contour;
            line2.Lineweight = Lineweight.W50;
            dxf.AddEntity(line2);
            Line line3 = new Line(v29, v18);
            line3.Layer = contour;
            line3.Lineweight = Lineweight.W50;
            dxf.AddEntity(line3);
            Line line4 = new Line(v18, v10);
            line4.Layer = contour;
            line4.Lineweight = Lineweight.W50;
            dxf.AddEntity(line4);
            Line line5 = new Line(v17, v14);
            line5.Layer = contour;
            line5.Lineweight = Lineweight.W50;
            dxf.AddEntity(line5);
            Line line6 = new Line(v28, v15);
            line6.Layer = contour;
            line6.Lineweight = Lineweight.W50;
            dxf.AddEntity(line6);
            Line line7 = new Line(v24, v16);
            line7.Layer = contour;
            line7.Lineweight = Lineweight.W50;
            dxf.AddEntity(line7);
            Line line8 = new Line(v16, v15);
            line8.Layer = contour;
            line8.Lineweight = Lineweight.W50;
            dxf.AddEntity(line8);
            Line line9 = new Line(v21, v20);
            line9.Layer = contour;
            line9.Lineweight = Lineweight.W50;
            dxf.AddEntity(line9);
            Line line10 = new Line(v22, v23);
            line10.Layer = contour;
            line10.Lineweight = Lineweight.W50;
            dxf.AddEntity(line10);
            List<Vector3> points00 = new List<Vector3>
           {

                new Vector3(v24.X,v24.Y, 0),
                new Vector3(v25.X,v25.Y, 0),
                new Vector3(v26.X,v26.Y, 0),
                new Vector3(v27.X,v27.Y, 0),
                new Vector3(v28.X,v28.Y, 0),
            };

            Spline spline00 = new Spline(points00);
            spline00.Layer = contour;
            DxfDocument doc00 = new DxfDocument();
            dxf.AddEntity(spline00);
            List<Vector3> points1 = new List<Vector3>
           {

                new Vector3(v29.X,v29.Y, 0),
                new Vector3(v30.X,v30.Y, 0),
                new Vector3(v31.X,v31.Y, 0),
                new Vector3(v32.X,v32.Y, 0),
                new Vector3(v33.X,v33.Y, 0),
            };

            Spline spline1 = new Spline(points1);
            spline1.Layer = contour;
            DxfDocument doc1 = new DxfDocument();
            dxf.AddEntity(spline1);




            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
